/*
 * square.fx
 *
 * Created on 25.10.2009, 21:34:43
 */

package justforfun.bombsquare;


import javafx.scene.Node;
import javafx.scene.shape.*;
import javafx.scene.paint.Color;
import justforfun.bombsquare.Constants.*;
import justforfun.bombsquare.myNode;

/**
 * @author civil
 */

public class Square extends myNode {
    public var fill: Color = Color.BLACK;
    public var stroke: Color = Color.BLUE;
    public var action: function(): Void = null;
    public var stepVal: Float = 0.25;
    public var notMoving: Boolean = true;
    

    override public function create(): Node {
        var rec: Rectangle = Rectangle {
            x: bind mx * x
            y: bind my * y
            width: mx
            height: my
            stroke: bind stroke
            fill: bind fill
        }
    }

    public function goTo(newx: Float, newy: Float): Void {
        //когда-нибудь здесь может быть будет код для анимации движения персонажа :3
        notMoving = false;
        x = newx;
        y = newy;
        notMoving = true;
    }

    public function up() {
        if (notMoving) {
            goTo(x, y - stepVal)
        }
    }


    public function down() {
        if (notMoving) {
            goTo(x, y + stepVal)
        }
    }

    public function left() {
        if (notMoving) {
            goTo(x - stepVal, y)
        }
    }

    public function right() {
        if (notMoving) {
            goTo(x + stepVal, y);
        }
    }

    public function kill () {
        if (action == null) {
            action()
        }
    }
}